local shiming = fk.CreateSkill({
    name = "sj5__shiming",
})

Fk:loadTranslationTable{
  ["sj5__shiming"] = "识命",
  [":sj5__shiming"] = "每轮限一次，势力与你相同的角色的准备阶段，你可以卜算3，然后从牌堆顶或牌堆底摸X张牌（X为势力与你相同的角色数）。若如此做，你变更势力。",
  
  ["$sj5__shiming1"] = "今天命在北，我等已尽人事。",
  ["$sj5__shiming2"] = "益州国疲民敝，非人力可续之。",
  
  
  ["#sj5__shiming-ask"] = "请选择从何处摸%arg张牌",
  ["#sj5__shiming-invoke"] = "变更势力",
}

shiming:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Start and player:hasSkill(shiming.name) and player.kingdom == target.kingdom and
    player:usedSkillTimes(shiming.name,Player.HistoryRound) == 0
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player,{skill_name = shiming.name})
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:askToGuanxing(player,{
    cards = room:getNCards(math.min(3, #room.draw_pile)),
    skill_name = shiming.name,
    })

    local n = #table.filter(room:getAlivePlayers(),function (t) return t.kingdom == player.kingdom end)
    local tb = room:askToChoice(player,{
      choices = {"Top","Bottom"},
      skill_name = shiming.name,
      prompt = "#sj5__shiming-ask:::"..n,
    })
    room:drawCards(player,n,shiming.name,tb == "Top" and "top" or "bottom")
    local kingdoms = {"wei", "shu", "wu", "qun", "jin"}
    local choices = table.simpleClone(kingdoms)
    table.removeOne(choices, player.kingdom)
    local choice = room:askToChoice(player,{
      choices = choices,
      skill_name = shiming.name,
      prompt = "#sj5__shiming-invoke",
      all_choices = kingdoms,
    })
    room:changeKingdom(player, choice, true)
  end,
})


return shiming